--[[ 编码: WMS-17-10 名称: 计划盘点容器-新增盘点单-确定后 作者:HAN 日期:2025-1-29 级别:固定 (说明本段代码在项目中不太会变化) 函数: AfterClickOK 功能: -- 获取查面板中输入的 站点 和 数量 创建盘点单 更改记录: --]] wms_base = require ("wms_base") -- 创建盘点单 -- wh_code 仓库编码 -- area_code 库区编码如果为空表示所有几乎融券 num 盘点容器数量如果=0说明盘点所有容器 local function create_count_order( strLuaDEID, cp_no, count_type, wh_code, area_code ) local nRet, strRetInfo if ( wh_code == nil or wh_code == '') then return 1, "wh_code 必须有值!" end if ( cp_no == nil or cp_no == '') then return 1, "cp_no 必须有值!" end if ( area_code == nil ) then area_code = '' end local strCondition = "S_CP_NO = '"..cp_no.."' AND (S_COUNT_NO = '' or S_COUNT_NO Is Null)" if ( area_code ~= '' ) then strCondition = strCondition.." AND S_AREA_CODE = '"..area_code.."'" end -- 获取待盘点的容器数量 nRet, strRetInfo = mobox.getDataObjCount( strLuaDEID, "CP_Count_Container", strCondition ) if ( nRet ~= 0 ) then return nRet, strRetInfo end local num = lua.StrToNumber( strRetInfo ) -- 检测符合条件的这些计划盘点容器是否有锁,如果有锁报错,不继续 -- 容器锁状态 不等于 0 local str_where = "N_LOCK_STATE <> 0 AND S_CODE IN ( Select S_CNTR_CODE From TN_CP_Count_Container Where "..strCondition..")" nRet, strRetInfo = mobox.existThisData( strLuaDEID, "Container", str_where ) if ( nRet ~= 0 ) then return 1, strRetInfo end if ( strRetInfo == "yes" ) then return 1, "计划盘点的容器中有些容器已经被锁定,不能继续盘点单创建操作!" end -- 创建盘点单 local count_order = m3.AllocObject(strLuaDEID,"Count_Order") count_order.cp_no = cp_no count_order.wh_code = wh_code count_order.area_code = area_code count_order.method = 1 -- 1 表示是人工盘点,这是新兴项目的要求 count_order.num = num count_order.count_type = count_type nRet, count_order = m3.CreateDataObj( strLuaDEID, count_order ) if (nRet ~= 0) then return 1, "创建【盘点单】失败!"..count_order end -- 容器加盘点锁 str_where = "N_LOCK_STATE = 0 AND S_CODE IN ( Select S_CNTR_CODE From TN_CP_Count_Container Where "..strCondition..")" local strSetSQL = "N_LOCK_STATE = 3" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Container", str_where, strSetSQL) if (nRet ~= 0) then return 1, "设置【容器】锁信息失败!"..strRetInfo end -- 计划盘点容器加盘点单号 strSetSQL = "S_COUNT_NO = '"..count_order.count_no.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "CP_Count_Container", strCondition, strSetSQL) if (nRet ~= 0) then return 1, "设置【容器】锁信息失败!"..strRetInfo end -- 生成【盘点容器货品明细】 local strClsID local strOrder = '' strCondition = "S_COUNT_NO = '"..count_order.count_no.."'" -- 多页查询 nRet, strRetInfo = mobox.queryDataObjAttr2( strLuaDEID, "CP_Count_Container", strCondition, strOrder, 100 ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "queryDataObjAttr2: "..strRetInfo) end if ( strRetInfo == '' ) then return end local success local queryInfo success, queryInfo = pcall( json.decode, strRetInfo ) if ( success == false ) then lua.Error( strLuaDEID, debug.getinfo(1), "queryDataObjAttr2 返回结果啊非法的JSON格式!" ) end local queryID = queryInfo.queryID local nPageCount = queryInfo.pageCount local nPage = 1 local dataSet = queryInfo.dataSet -- 查询出来的数据集 local datajson = {} datajson.count_type = count_type while (nPage <= nPageCount) do for n = 1, #dataSet do -- 考虑到生成盘点货品明细的时间会较长用 WFP 来进行处理 local add_wfp = {} add_wfp.wfp_type = 1 -- 触发数据对象事件(指定数据对象标识) add_wfp.datajson = datajson add_wfp.cls = "CP_Count_Container" add_wfp.obj_id = dataSet[n].id add_wfp.trigger_event = "生成盘点货品明细" nRet, strRetInfo = m3.AddSysWFP( strLuaDEID, add_wfp ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end end nPage = nPage + 1 if ( nPage <= nPageCount ) then -- 取下一页 nRet, strRetInfo = mobox.queryDataObjAttr2( queryID, nPage) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "queryDataObjAttr2失败! nPage="..nPage.." "..strRetInfo ) end queryInfo = json.decode(strRetInfo) dataSet = queryInfo.dataSet end end return 0 end function AfterClickOK ( strLuaDEID ) local nRet, strRetInfo local area_code -- 获取 库区编码,盘点类型 nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "Method" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end local obj_attrs = json.decode( strRetInfo ) local method = lua.Get_StrAttrValue( obj_attrs[1].value ) local runtime_paramter nRet, runtime_paramter = m3.GetRuntimeParam(strLuaDEID) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "GetRuntimeParam失败! "..runtime_paramter ) end lua.Debug( strLuaDEID, debug.getinfo(1), "runtime_paramter", runtime_paramter ) -- 获取主数据对象【盘点计划】 local master = runtime_paramter.master if ( master == nil ) then lua.Error( strLuaDEID, debug.getinfo(1), "运行时参数缺少master属性! " ) end local count_plan nRet, count_plan = m3.GetDataObject( strLuaDEID, master.clsId, master.objId ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), count_plan ) end local cp_no = count_plan.cp_no local count_type = count_plan.type local wh_code = count_plan.wh_code if ( cp_no == nil or cp_no == '') then lua.Error( strLuaDEID, debug.getinfo(1), "无法获取计划盘点号! " ) end local b_state = lua.StrToNumber( master.objAttr["N_B_STATE"] ) if ( b_state ~= 2 ) then lua.Error( strLuaDEID, debug.getinfo(1), "盘点计划的状态非执行状态,无法创建盘点单! " ) end lua.Debug( strLuaDEID, debug.getinfo(1), "count_type", count_type ) -- 根据 method 来创建【盘点单】 local strCondition local strOrder = '' if ( method == "根据库区分别生成盘点单" ) then -- 获取目前计划盘点容器的库区 strCondition = "S_CP_NO ='"..cp_no.."' AND (S_COUNT_NO ='' or S_COUNT_NO Is Null)" nRet, strRetInfo = mobox.groupDataObjAttr( strLuaDEID, "CP_Count_Container", strCondition, "S_AREA_CODE", strOrder) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "无法从【CP_Count_Container】获取库区信息"..strRetInfo ) end if ( strRetInfo == '' ) then lua.Error( strLuaDEID, debug.getinfo(1), "检查一下计划盘点容器是否已经计算出货位?" ) end local area_group = json.decode( strRetInfo ) -- 库区 local n for n = 1, #area_group do nRet, strRetInfo = create_count_order( strLuaDEID, cp_no, count_type, wh_code, area_group[n].value ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_count_order 失败! "..strRetInfo ) end end else nRet, strRetInfo = create_count_order( strLuaDEID, cp_no, count_type, wh_code ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_count_order 失败! "..strRetInfo ) end end end